package com.chookss.home.search.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.WebCommonActivity;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.base.Token;
import com.chookss.home.search.entity.SearchAllEntity;
import com.chookss.tools.NavigationTools;
import com.chookss.tools.Utils;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class SearchGonggaoAdapter extends BaseQuickAdapter<SearchAllEntity.NoticeBean.ListBean, BaseViewHolderEx> {
    private Context context;
    private int width, height;
    private String key;

    public SearchGonggaoAdapter(int layoutResId, Context context, @Nullable List<SearchAllEntity.NoticeBean.ListBean> data) {
        super(layoutResId, data);
        this.context = context;

    }

    @Override
    protected void convert(BaseViewHolderEx helper, SearchAllEntity.NoticeBean.ListBean item) {
        TextView tvTiltle = helper.getView(R.id.tvSearchGonggaoTitle);
        TextView tvSearchType = helper.getView(R.id.tvSearchGonggaoContains);
        TextView tvSearchProvider = helper.getView(R.id.tvSearchGonggaoProvider);
        tvTiltle.setText(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color), item.getNoticeTitle(), key));
        if (!Utils.isNull(item.getNoticeContent())) {
            tvSearchType.setText("包含：");
            tvSearchType.append(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color), item.getNoticeContent(), key));
        }
        if (!Utils.isNull(item.getEmployeeName())) {
            tvSearchProvider.setText("发布人：");
            tvSearchProvider.append(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color), item.getEmployeeName(), key));

        }
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavigationTools.saveUseRecord(context,"1","01");
                Intent intent = new Intent(context, WebCommonActivity.class);
                String addressType = "";
                if (Urls.baseUrl.contains("dev_kmer")) {
                    addressType = "1";
                } else {
                    addressType = "0";
                }
                String url = Urls.webBaseUrl + "indexNotice.html#/noticeDetail?noticeCode=" + item.getNoticeCode() + "&token=" + Token.INSTANCE.getToken() + "&statusHeight=" + Utils.getStatusBarHeightDp(context) + "&time=" + System.currentTimeMillis() + "&addressType=" + addressType;
                intent.putExtra("url", url);
                intent.putExtra("waterMark", "12");
                context.startActivity(intent);
            }
        });
    }

    public void setKey(String key) {
        this.key = key;
    }
}
